Skip to content

refactor: migrate lib.autoExternal to output.autoExternal - #1641

Merged
Timeless0911 merged 23 commits into
mainfrom
refactor/migrate-auto-external-to-rsbuild
Jul 21, 2026
Merged

refactor: migrate lib.autoExternal to output.autoExternal#1641
Timeless0911 merged 23 commits into
mainfrom
refactor/migrate-auto-external-to-rsbuild

Conversation

@elecmonkey

@elecmonkey elecmonkey commented May 12, 2026

Copy link
Copy Markdown
Member

Migrated lib.autoExternal to reuse Rsbuild's native output.autoExternal (available since Rsbuild 2.0.7).

The deprecated lib.autoExternal field is preserved that maps to output.autoExternal with a deprecation warning.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 13, 2026

Copy link
Copy Markdown

Deploying rslib with  Cloudflare Pages  Cloudflare Pages

Latest commit: c5fb629
Status: ✅  Deploy successful!
Preview URL: https://26c51f88.rslib.pages.dev
Branch Preview URL: https://refactor-migrate-auto-extern.rslib.pages.dev

View logs

@elecmonkey
elecmonkey force-pushed the refactor/migrate-auto-external-to-rsbuild branch from b2e6446 to 1a5b36f Compare May 21, 2026 06:09
@elecmonkey
elecmonkey marked this pull request as ready for review May 21, 2026 06:09
Copilot AI review requested due to automatic review settings May 21, 2026 06:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates Rslib’s dependency auto-externalization behavior from the legacy lib.autoExternal option to Rsbuild’s output.autoExternal, aligning implementation with Rsbuild’s built-in capability while keeping backward compatibility via a deprecation shim.

Changes:

  • Add output.autoExternal documentation (EN/ZH) and mark lib.autoExternal as deprecated in docs and public config typings.
  • Refactor core config composition to rely on output.autoExternal (and remove the previous custom composeAutoExternalConfig implementation and its unit tests).
  • Update CLI option wiring and test expectations/snapshots to reflect the new configuration location.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
website/docs/zh/config/rsbuild/output.mdx Add output.autoExternal docs and update output.externals wording to reference it.
website/docs/zh/config/lib/auto-external.mdx Add deprecation warning pointing to output.autoExternal.
website/docs/en/config/rsbuild/output.mdx Add output.autoExternal docs and update output.externals wording to reference it.
website/docs/en/config/lib/auto-external.mdx Add deprecation warning pointing to output.autoExternal.
tests/integration/externals/index.test.ts Remove the module-import warning integration test that depended on the old warning logic.
tests/integration/auto-external/index.test.ts Remove the module-import warning integration test and simplify imports accordingly.
packages/core/tests/external.test.ts Remove unit tests for the deleted composeAutoExternalConfig.
packages/core/tests/config.test.ts Update CLI snapshot expectations for new output.autoExternal location.
packages/core/tests/cli.test.ts Assert CLI populates lib.output.autoExternal instead of lib.autoExternal.
packages/core/tests/snapshots/config.test.ts.snap Update snapshots to reflect externals ordering and output.autoExternal presence.
packages/core/src/types/config.ts Deprecate lib.autoExternal in typings and add output.autoExternal override typing/docs.
packages/core/src/config.ts Remove custom auto-externalization + warning logic; set defaults via output.autoExternal; add deprecation shim.
packages/core/src/cli/init.ts Wire --auto-external CLI flag to lib.output.autoExternal.
Comments suppressed due to low confidence (2)

website/docs/en/config/lib/auto-external.mdx:15

  • The page frontmatter/intro still describes lib.autoExternal as an active configuration, but the option is now deprecated. Update the page description/intro to clearly state it’s kept for backward compatibility and point readers to output.autoExternal as the canonical option.
# lib.autoExternal

:::warning
`lib.autoExternal` is deprecated. Please use [output.autoExternal](/config/rsbuild/output#outputautoexternal) instead.
:::

:::info

`autoExternal` is a specific configuration for bundle mode. It will not take effect in bundleless mode (set [lib.bundle](/config/lib/bundle) to `false`) since deps will not be bundled in bundleless mode.

website/docs/zh/config/lib/auto-external.mdx:15

  • 当前页面的描述仍然把 lib.autoExternal 当作主要配置项,但这里已标记为废弃。建议同步更新页面的描述/开头说明,明确这是兼容性保留配置,并引导用户迁移到 output.autoExternal
# lib.autoExternal

:::warning
`lib.autoExternal` 已废弃,请使用 [output.autoExternal](/config/rsbuild/output#outputautoexternal) 代替。
:::

:::info

`autoExternal` 是 bundle 模式的特定配置。在 bundleless 模式(将 [lib.bundle](/config/lib/bundle) 设置为 `false`)下不会生效,因为 bundleless 模式下依赖不会被打包。

Comment thread packages/core/src/config.ts Outdated
Comment thread packages/core/src/config.ts Outdated
Comment thread website/docs/en/config/rsbuild/output.mdx
@elecmonkey
elecmonkey requested a review from Timeless0911 May 21, 2026 06:25
@Timeless0911 Timeless0911 changed the title refactor: migrate lib.autoExternal to output.autoExternal to leverage Rsbuild's capability refactor: migrate lib.autoExternal to output.autoExternal May 26, 2026
@Timeless0911

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 71232855db

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/config.ts
@elecmonkey
elecmonkey marked this pull request as draft May 27, 2026 02:09
@elecmonkey
elecmonkey force-pushed the refactor/migrate-auto-external-to-rsbuild branch from 7123285 to 99d1fa6 Compare May 27, 2026 02:43
@elecmonkey
elecmonkey marked this pull request as ready for review May 27, 2026 02:47
Comment thread packages/core/tests/config.test.ts
…-external-to-rsbuild

# Conflicts:
#	packages/core/src/config.ts
…-external-to-rsbuild

# Conflicts:
#	packages/core/src/config.ts
#	packages/core/tests/__snapshots__/config.test.ts.snap
#	tests/integration/externals/index.test.ts
Comment thread tests/integration/externals/index.test.ts
Comment thread website/docs/zh/guide/advanced/third-party-deps.mdx Outdated
Comment thread website/docs/zh/guide/advanced/third-party-deps.mdx Outdated
Comment thread website/docs/zh/guide/advanced/third-party-deps.mdx Outdated
Comment thread website/docs/zh/guide/advanced/third-party-deps.mdx Outdated
Comment thread website/docs/zh/guide/advanced/third-party-deps.mdx Outdated
Comment thread packages/core/tests/config.test.ts Outdated
@elecmonkey
elecmonkey marked this pull request as draft July 18, 2026 10:30
@elecmonkey
elecmonkey marked this pull request as ready for review July 21, 2026 02:51
Comment thread packages/core/tests/config.test.ts
Comment thread website/docs/zh/guide/advanced/third-party-deps.mdx Outdated
Comment thread website/docs/zh/guide/advanced/third-party-deps.mdx Outdated
Comment thread website/docs/zh/guide/advanced/third-party-deps.mdx Outdated
@elecmonkey
elecmonkey force-pushed the refactor/migrate-auto-external-to-rsbuild branch from dcc6c66 to 003de77 Compare July 21, 2026 03:50
@elecmonkey
elecmonkey requested a review from Timeless0911 July 21, 2026 05:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c5fb629875

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1750 to +1751
libConfig.autoExternal !== undefined &&
libConfig.output?.autoExternal === undefined

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve shared deprecated autoExternal settings

When users still rely on the documented top-level deprecated setting, e.g. autoExternal: false as a shared lib option, this shim never copies it into userConfig.output.autoExternal because it only checks the per-lib item. The merged userConfig.autoExternal is later omitted from the final Rsbuild config, while composeFormatConfig adds output.autoExternal: true for ESM/CJS, so those projects silently start externalizing dependencies instead of bundling them.

Useful? React with 👍 / 👎.

Comment on lines +1420 to +1423
autoExternal:
libConfig.output?.autoExternal ??
libConfig.autoExternal ??
isIntermediateOutputFormat(format),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor autoExternal exclude/packageJson for bundled dts

When dts.bundle is enabled and users configure Rsbuild-only options such as output.autoExternal: { exclude: ['foo'] } or packageJson, passing this object straight through makes rsbuild-plugin-dts ignore those fields: its bundled-package calculation only understands dependency booleans and always reads the root package.json. The JS build will bundle excluded packages (or read a different package file), but the declaration bundle will still treat them as external, so emitted types no longer match the JS dependency handling unless users manually duplicate dts.bundle.bundledPackages.

Useful? React with 👍 / 👎.

@Timeless0911
Timeless0911 merged commit 2add0d0 into main Jul 21, 2026
12 checks passed
@Timeless0911
Timeless0911 deleted the refactor/migrate-auto-external-to-rsbuild branch July 21, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants